package com.tyqx.hashchainbiz;

// import com.alibaba.fastjson.JSON;

import com.tyqx.hashchainbiz.service.JZTAttachmentBusinessService;
import com.tyqx.hashchainbiz.service.JZTLogisticsService;
import com.tyqx.hashchainbiz.service.NoHashValueJsonService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;

@Component
public class SchedulerSuccess {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Resource
    private JZTLogisticsService jztLogisticsService;

    @Resource
    private NoHashValueJsonService noHashValueJsonService;

    @Resource
    private JZTAttachmentBusinessService jztAttachmentBusinessService;

    ///@Async
    //表示每隔秒
//    @Scheduled(fixedRate = 60 * 1000 * 10)
    /*@Scheduled(fixedDelay = 1000 * 10)
    public void testTasks() throws Exception {
        System.out.println("迁移上链信息定时任务执行时间：" + dateFormat.format(new Date()));
        Integer status = 1;
        List<NoHashValueJson> noHashValueJsonList = noHashValueJsonService.selectByStatus(status);
        if (EmptyUtils.isNotEmpty(noHashValueJsonList)) {
            for (NoHashValueJson noHashValueJson : noHashValueJsonList) {
                Gson gson = new GsonBuilder()
                        .setDateFormat("yyyy-MM-dd HH:mm:ss")
                        .create();
                String recordJson = noHashValueJson.getRecordJson();
                HashIndex hashIndex1 = new HashIndex();
                hashIndex1.setBlockNum(noHashValueJson.getBlockNum());
                hashIndex1.setHashValue(noHashValueJson.getHashValue());
                hashIndex1.setRootHashValue(noHashValueJson.getRootHashValue());
                hashIndex1.setTxId(noHashValueJson.getTxId());
                hashIndex1.setTxTimeStamp(noHashValueJson.getTxTimeStamp());
                if ("jzt_logistics".equals(noHashValueJsonList.get(0).getHashTableName())) {
                    JZTLogistics jztLogistics = gson.fromJson(recordJson, JZTLogistics.class);
                    jztLogistics.setHashValue(noHashValueJson.getHashValue());
                    jztLogistics.setRootHashValue(noHashValueJson.getRootHashValue());
                    jztLogisticsService.recordJZTLogistics(noHashValueJson.getHashValue(), hashIndex1, jztLogistics);
                }else if ("jzt_attachment_businesss".equals(noHashValueJsonList.get(0).getHashTableName())) {
                    JZTAttachmentBusiness jztAttachmentBusiness = gson.fromJson(recordJson, JZTAttachmentBusiness.class);
                    jztAttachmentBusiness.setHashValue(noHashValueJson.getHashValue());
                    jztAttachmentBusiness.setRootHashValue(noHashValueJson.getRootHashValue());
                    jztAttachmentBusinessService.recordJZTAttachmentBusiness(noHashValueJson.getHashValue(), hashIndex1, jztAttachmentBusiness);
                }
            }
        }
        System.out.println("迁移上链信息定时任务结束时间：" + dateFormat.format(new Date()));
    }*/


}